package FenxiaoService

import (
	"context"
	"gdshop-back-end-go/client-api/app/request/FenxiaoReq"
	toolsDb "gdshop-back-end-go/common/db"
	"gdshop-back-end-go/common/response"
	"gdshop-back-end-go/common/tools"
	"github.com/gogf/gf/frame/g"
)

func BillList(ctx context.Context, parames *FenxiaoReq.BillList) *response.JsonResponse {
	count, err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "fenxiao_user_invoice").Fields("1").Where("member_id", parames.MemberId).Count()
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	all, err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "fenxiao_user_invoice").Where("member_id", parames.MemberId).
		Fields("invoice_no,invoice_type,invoice_fee,create_at").Order("id DESC").
		Page(parames.Page, parames.PageSize).All()
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}

	return response.SuccessByRequestMessageData(nil, "", g.Map{
		"page_info": tools.GetPageInfo(count, parames.Page, parames.PageSize),
		"list":      all.List(),
	})
}
